package com.googlecode.flair
{
	import com.googlecode.flair.builder.FlairBuilder;
	import com.googlecode.flair.builder.FlairBuilderView;
	import com.googlecode.flair.builder.FlairOutlineView;
	import com.googlecode.flair.mvc.TitleWindowController;
	
	import flash.display.DisplayObject;
	
	import flexlib.mdi.containers.MDICanvas;
	
	import mx.containers.TitleWindow;
	import mx.managers.PopUpManager;
	
	[Bindable]
	public class DesignAdvisor extends TitleWindowController
	{
		
		public static var instance : DesignAdvisor = null;
		
		private var outline : FlairOutlineView = null;
		private var componentView : FlairComponentView = null;
		private var flairBuilder : FlairBuilder = null;
		
		public function DesignAdvisor()
		{
			instance = this;
		}
		
		public final function design(flairComponent : IFlairComponent) : void 
		{
			//var oldComponent : IFlairComponent = this.currentComponent;
			FlairModelLocator.instance.currentComponent = flairComponent;
			FlairModelLocator.instance.advisedComponent = flairComponent.component;
//			if (componentView) {
//				componentView.refresh();
//			}
			if (flairBuilder) {
				flairBuilder.edit(flairComponent);
			}
		}
		
		
		public final function showFor(parent : DisplayObject, designedComponent : IFlairComponent) : void {
			//PopUpManager.removePopUp(designAdvisorView);
			//outline = new FlairOutlineView();
			//PopUpManager.addPopUp(outline, parent, false);
			
			//var theComponent : IFlairComponent = FlairModelLocator.instance.currentComponent;
			
			var content : FlairContentView = new FlairContentView();
			MDICanvas(parent).addChild(content);
			MDICanvas(parent).windowManager.add(content);
//			PopUpManager.addPopUp(content, parent, false);
			
//			if (!(parent is TitleWindow)) {
			content.x = (parent.width - content.width) / 2;
			content.y = parent.height - content.height - 10;
//			}
			
			//componentView = new FlairComponentView();
			//componentView.designerAdvisor = this;
			//PopUpManager.addPopUp(componentView, parent, false);
			
			flairBuilder = new FlairBuilder();
			var flairBuilderView : FlairBuilderView = new FlairBuilderView();
			flairBuilderView.controller = flairBuilder;
//			PopUpManager.addPopUp(flairBuilderView, parent, false);
//			if (!(parent is TitleWindow)) {
//			}
			MDICanvas(parent).addChild(flairBuilderView);
			MDICanvas(parent).windowManager.add(flairBuilderView);
			flairBuilderView.width = 300;
			flairBuilderView.height = parent.height - 50;
			flairBuilderView.x = (parent.width - flairBuilderView.width) - 10;
			flairBuilderView.y = 30;
			design(designedComponent);
		} 
		
		public final override function showCloseButton():Boolean 
		{
			return false;
		}
		
		
		

	}
	
}